<template>
  <el-container>
    <el-card class="box-card" shadow="hover">
      <div class="card-title">管理员详情</div>
      <el-table :data="detailData">
        <el-table-column property="detailName" label="详情名"></el-table-column>
        <el-table-column property="detailValue" label="详情值"></el-table-column>
      </el-table>
    </el-card>
  </el-container>
</template>

<script>
  export default {
    data() {
      return {
        administratorData: {},
        detailData: [],
      }
    },
    methods: {
      getGenderWord(genderData) {
        if (genderData == "男" || genderData == "man" || genderData == "male" || genderData == "nan")
          return "男";
        else
          return "女";
      },
      getAdministratorData() {
        let username = JSON.parse(localStorage.getItem("user")).username;
        this.$axios.get(`http://localhost:8080/administrator/username/${username}`).then(result => {
          if (result.data.code == 200) {
            this.administratorData = result.data.data;
            this.detailData = [];
            let detailKeys = Object.keys(this.administratorData);
            for (let i of detailKeys) {
              if (i == "id") {
                this.detailData.push({"detailName": "id", "detailValue": this.administratorData[i]});
              } else if (i == "name") {
                this.detailData.push({"detailName": "姓名", "detailValue": this.administratorData[i]});
              } else if (i == "username") {
                this.detailData.push({"detailName": "账号", "detailValue": this.administratorData[i]});
              } else if (i == "gender") {
                this.detailData.push({"detailName": "性别", "detailValue": this.getGenderWord(this.administratorData[i])});
              } else if (i == "birth") {
                this.detailData.push({"detailName": "生日", "detailValue": this.administratorData[i]});
              } else if (i == "phone") {
                this.detailData.push({"detailName": "电话", "detailValue": this.administratorData[i]});
              } else if (i == "hiredate") {
                this.detailData.push({"detailName": "入职时间", "detailValue": this.administratorData[i]});
              }
            }
          }
        });
      }
    },
    mounted() {
      this.getAdministratorData();
    },
  }
</script>

<style>
  .box-card {
    width: 650px;
    margin: 32px auto;
  }
  .card-title {
    margin-top: 4px;
    padding-bottom: 12px;
    margin-bottom: 4px;
    border-bottom: 1px solid lightgray;
    font-weight: bold;
  }
</style>